package shiro.redis;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

public class RedisCacheManager implements CacheManager {
 
    @SuppressWarnings("rawtypes")
	private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
 
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException 
    {
        Cache c = caches.get(name);
 
        if (c == null) 
        {
        	RedisManager.init();
            c = new RedisCache<K, V>();
            caches.put(name, c);
        }
        return c;
    }
 
}